package svc

import (
	"github.com/zeromicro/go-zero/core/stores/cache"
	"mscoin-common/msdb"
	"ucenter/internal/config"
	"ucenter/internal/database"
)

type ServiceContext struct {
	Config config.Config
	Cache  cache.Cache //缓存接口
	Db     *msdb.MsDB  //数据库连接
}

func NewServiceContext(c config.Config) *ServiceContext {
	//手动创建一个redis对象
	redisCache := cache.New(
		c.CacheRedis,
		nil,
		cache.NewStat("mscoin"),
		nil,
		func(o *cache.Options) {})

	return &ServiceContext{
		Config: c,
		Cache:  redisCache, //给上下文赋值
		Db:     database.ConnMysql(c.Mysql.DataSource),
	}
}
